﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using AbcCorp.DTO;
using AbcCorp.BLO;
namespace AbcCorp.CategoryService
{
    public class CategoryService : ICategoryService
    {
        public IList<Category> GetCategories()
        {
            IList<Category> lstCategory =  new List<Category>();
            var categoryBlo = new CategoryBlo();
            var lstCategoryDto = categoryBlo.GetCategories();
            if (lstCategoryDto == null) return null;

            foreach (var categoryDto in lstCategoryDto)
            {
                var category = new Category();
                CopyObject<CategoryDto, Category>.CopyProperties(categoryDto, category);
                lstCategory.Add(category);
            }
            return lstCategory;
        }

        public Category GetCategory(int catid)
        {
            var category = new Category();
            var categoryBlo = new CategoryBlo();
            var categoryDto = categoryBlo.GetCategory(catid);
            if (categoryDto == null) return null;
            CopyObject<CategoryDto, Category>.CopyProperties(categoryDto, category);
            return category;
        }

        public bool AddCategory(Category newCategory)
        {
            var categoryBlo = new CategoryBlo();
            var categoryDto = new CategoryDto();
            CopyObject<Category, CategoryDto>.CopyProperties(newCategory, categoryDto);
            return categoryBlo.AddCategory(categoryDto);
        }
    }
}
